package org.example.servicemanage.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
@Slf4j
public class SpringRabbit {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    public void send(String queueName, String message) {
        CorrelationData cd = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(queueName, (Object) message, cd);
    }


    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "delay.queue", durable = "true"),
                    exchange = @Exchange(name = "delay.exchange", delayed = "true"),
                    key = {"hi"}
            )
    )
    public void receive_3(String message) {
        log.info("receive_3: {}", message);
    }
}
